package org.dragon.models;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 * Author:     Zhao Yan
 * DateTime:   2023/5/23 9:59
 */
public class AppConfig {

    @NotBlank
    public String title = "CMS";

    @NotBlank
    public String frontEndUrl = "http://cool.com";

    @NotNull
    public GiteeConfig giteeConfig;

    public AppConfig() {
    }

    public static AppConfig fromContent(String content) {
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            return objectMapper.readValue(content, AppConfig.class);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return null;
    }

    public String toContent() {
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return null;
    }
}
